import { INCREMENT_COUNTER, DECREMENT_COUNTER, SET_COUNTER_ASYNCTIME } from '../actions/counter'

//reducer其实也是个方法而已,参数是state和action,返回值是新的state
export default function counter(state={count:0}, action) {
  switch (action.type) {
    case INCREMENT_COUNTER:
      return {
        ...state,
        count: state.count+1
      }
    case DECREMENT_COUNTER:
    return {
      ...state, 
      count: state.count-1
    };
     case SET_COUNTER_ASYNCTIME:
      return {
        ...state,
        delayTime: action.delaytime
      }
    default:
      return state
  }
}
